#ifndef _L2_PROTOCOL_
#define _L2_PROTOCOL_

#include "types.h"

#define MAX_SEQ 15      // SEQ numbers 0.. 15
#define RECEIVER_WINDOW_SIZE ((MAX_SEQ + 1) / 2)
#define SENDER_WINDOW_SIZE RECEIVER_WINDOW_SIZE

/***
 * Don't change values of l2_frame_type_t
 * Their bit order understanding is directly used
 * in the code
 **/
typedef enum
{
  DATA_FRAME = 1,
  ACK_FRAME = 2,
  DATA_ACK_FRAME = 3
}l2_frame_type_t;

/*************************
 * L2 frame header
 ************************/
typedef struct
{
  l2_frame_type_t frame_type;
 
  #ifdef USE_NAK_BITMAP
  #if MAX_SEQ > 32
  #error "USE_NAK_BITMAP: MAX_SEQ numbers greater than 32"
  #endif

  uint32_t nak_bitmap;
  #else
  uint16_t nak_seq;
  #endif

  uint16_t data_seq;
  uint16_t ack_seq;

  uint16_t payload_size;
  uint8_t payload[0];
  
}l2_hdr_t;

#endif
